Test Series - java script

Test Number 26/92

Q: What is the property to access the first child of a node?
A. timestamp.Child1
B. timestamp.Child(1)
C. timestamp.Child(0)
D. timestamp.firstChild
Solution: The first child of a node can be accessed using the firstChild property. firstChild returns the first child node as an element node, a text node or a comment node (depending on which one’s first).
Q: What are the properties supporting CSS styles for a document element?
A. style and font
B. style and className
C. size and style
D. className and font
Solution: Each Element object has style and className properties that allow scripts to specify CSS styles for a document element or to alter the CSS class names that apply to the element. firstChild returns the first child node as an element node, a text node or a comment node (depending on which one’s first).
Q: Which of the following object belongs to the style property?
A. Element
B. Window
C. Location
D. Dynamic
Solution: Each Element object has style and className properties that allow scripts to specify CSS styles for a document element or to alter the CSS class names that apply to the element.
Q: What is the purpose of the event handlers in the JavaScript?
A. Adds innerHTML page to the code
B. Performs handling of exceptions and occurrences
C. Allows JavaScript code to alter the behaviour of windows
D. Change the server location
Solution: Event handlers allow JavaScript code to alter the behavior of windows, of documents, and of the elements that make up those documents.
Q: Which handler is triggered when the content of the document in the window is stable and ready for manipulation?
A. onload
B. manipulate
C. create
D. onkeypress
Solution: One of the most important event handlers is the onload handler of the Window object. It is triggered when the content of the document displayed in the window is stable and ready to be manipulated. JavaScript code is commonly wrapped within an onload event handler.
Q: When a program contains extensive use of event handlers, which of the following is necessary?
A. Modular functions
B. Nested functions
C. Split up programs
D. Global variables
Solution: Nested functions are those functions in which one function is defined inside another function. Nested functions are common in client-side JavaScript, because of its extensive use of event handlers.
Q: What is the JavaScript code snippet to find all container elements with class “reveal”?
A. var elements = document.getElementsByClassName(“reveal”);
B. var elements = document.getElementByClassName(“reveal”);
C. var elements = document.getElementByName(“reveal”);
D. var elements = document.getElementsClassName(“reveal”);
Solution: The getElementsByClassName() method returns a collection of all elements in the document with the specified class name, as a NodeList object. The above code snippet finds all container elements with class “reveal”.
Q: What is the JavaScript code snippet to update the content of the timestamp element when the user clicks on it?
A. timestamp.onLoad = function() { this.innerHTML = new Date().toString(); }
B. timestamp.onclick = function() { this.innerHTML = new Date().toString(); }
C. timestamp.onload = function() { this.innerHTML = new Date().toString(); }
D. timestamp.onclick = function() { innerHTML = new Date().toString(); }
Solution: onclick() function is used to handle events when the user clicks on the mouse. The above code snippet updates the content of the timestamp element when the user clicks on it.
Q: Which of the following is not an object?
A. Element
B. Location
C. Position
D. Window
Solution: There is no object called Position. Whereas elements, location and window are a predefined object in JavaScript.
Q: What is the JavaScript code snippet to change the class and let the stylesheet specify the details?
A. timestamp.className = “highlight”;
B. timestamp.className = “change”;
C. timestamp.className = “specify”;
D. timestamp.className = “move”;
Solution: Each Element object has style and className properties that allow scripts to specify CSS styles for a document element or to alter the CSS class names that apply to the element. The above code snippet changes the class and lets the stylesheet specify the details.

You Have Score    /10